USE [DefectManagementSystem];
GO
----------------------------------------------------------------------------------------
--  LEUNG
----------------------------------------------------------------------------------------
IF OBJECT_ID('[dbo].[usp_dms_DefectStatusSelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_dms_DefectStatusSelect] 
END 
GO
CREATE PROC [dbo].[usp_dms_DefectStatusSelect] 
    @DefectStatus_Id INT = NULL
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [DefectStatus_Id], [DefectStatusName] 
	FROM   [dbo].[dms_DefectStatus] 
	WHERE  ([DefectStatus_Id] = @DefectStatus_Id OR @DefectStatus_Id IS NULL) 

	COMMIT
GO
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

IF OBJECT_ID('[dbo].[usp_dms_DefectTypeSelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_dms_DefectTypeSelect] 
END 
GO
CREATE PROC [dbo].[usp_dms_DefectTypeSelect] 
    @DefectType_Id INT = NULL 
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [DefectType_Id], [DefectTypeName] 
	FROM   [dbo].[dms_DefectType] 
	WHERE  ([DefectType_Id] = @DefectType_Id OR @DefectType_Id IS NULL) 

	COMMIT
GO

----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

IF OBJECT_ID('[dbo].[usp_dms_OriginSelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_dms_OriginSelect] 
END 
GO
CREATE PROC [dbo].[usp_dms_OriginSelect] 
    @Origin_Id INT = NULL
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [Origin_Id], [OriginName] 
	FROM   [dbo].[dms_Origin] 
	WHERE  ([Origin_Id] = @Origin_Id OR @Origin_Id IS NULL) 

	COMMIT
GO
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

IF OBJECT_ID('[dbo].[usp_dms_PrioritySelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_dms_PrioritySelect] 
END 
GO
CREATE PROC [dbo].[usp_dms_PrioritySelect] 
    @Priority_Id INT = NULL 
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [Priority_Id], [PriorityName] 
	FROM   [dbo].[dms_Priority] 
	WHERE  ([Priority_Id] = @Priority_Id OR @Priority_Id IS NULL) 

	COMMIT
GO
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

IF OBJECT_ID('[dbo].[usp_dms_ProjectStatusSelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_dms_ProjectStatusSelect] 
END 
GO
CREATE PROC [dbo].[usp_dms_ProjectStatusSelect] 
    @ProjectStatus_Id INT = NULL 
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [ProjectStatus_Id], [ProjectStatusName] 
	FROM   [dbo].[dms_ProjectStatus] 
	WHERE  ([ProjectStatus_Id] = @ProjectStatus_Id OR @ProjectStatus_Id IS NULL) 

	COMMIT
GO
IF OBJECT_ID('[dbo].[usp_dms_QCActivitySelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_dms_QCActivitySelect] 
END 
GO
CREATE PROC [dbo].[usp_dms_QCActivitySelect] 
    @QCActivity_Id INT = NULL 
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [QCActivity_Id], [QCActivityName] 
	FROM   [dbo].[dms_QCActivity] 
	WHERE  ([QCActivity_Id] = @QCActivity_Id OR @QCActivity_Id IS NULL) 

	COMMIT
GO
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

IF OBJECT_ID('[dbo].[usp_dms_SeveritySelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_dms_SeveritySelect] 
END 
GO
CREATE PROC [dbo].[usp_dms_SeveritySelect] 
    @Severity_Id INT = NULL
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [Severity_Id], [SeverityName] 
	FROM   [dbo].[dms_Severity] 
	WHERE  ([Severity_Id] = @Severity_Id OR @Severity_Id IS NULL) 

	COMMIT
GO

----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

IF OBJECT_ID('[dbo].[usp_ProductSelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_ProductSelect] 
END 
GO
CREATE PROC [dbo].[usp_ProductSelect] 
    @Product_Id INT = NULL
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [Product_Id], [ProductName] 
	FROM   [dbo].[Product] 
	WHERE  ([Product_Id] = @Product_Id OR @Product_Id IS NULL) 

	COMMIT
GO
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

IF OBJECT_ID('[dbo].[usp_ProductTypeSelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_ProductTypeSelect] 
END 
GO
CREATE PROC [dbo].[usp_ProductTypeSelect] 
    @ProductType_Id INT = NULL
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [ProductType_Id], [ProductTypeName] 
	FROM   [dbo].[ProductType] 
	WHERE  ([ProductType_Id] = @ProductType_Id OR @ProductType_Id IS NULL) 

	COMMIT
GO
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

IF OBJECT_ID('[dbo].[usp_ProjectSelect]') IS NOT NULL
BEGIN 
    DROP PROC [dbo].[usp_ProjectSelect] 
END 
GO
CREATE PROC [dbo].[usp_ProjectSelect] 
    @Project_Id INT = NULL 
AS 
	SET NOCOUNT ON 
	SET XACT_ABORT ON  

	BEGIN TRAN

	SELECT [Project_Id], [ProjectName], [Description], [CreatedDate], [ProjectStatus_Id] 
	FROM   [dbo].[Project] 
	WHERE  ([Project_Id] = @Project_Id OR @Project_Id IS NULL) 

	COMMIT
GO

----------------------------------------------------------------------------------------
-- END LEUNG
----------------------------------------------------------------------------------------
